#Load packages
library(tidyverse)
library(quantmod)
library(ggpubr)
library(readxl)
library(lubridate)
library(writexl)
library(zoo)
library(Rcpp)
library(readxl)
#install.packages("ggpubr")
#install.packages("writexl")
#install.packages('Rcpp')

# Set working directory.
setwd("C:\\work_temp\\Evidence_from_real_estate_funds\\growth_rates")
dataPath = "C:\\work_temp\\Evidence_from_real_estate_funds\\data_backup"

#TASK02 - Country Specific Plots 2020
#GERMANY
#Data Import 
dataGer = read_excel(paste(dataPath, "\\Germany_2020.xlsx", sep=""))

z = dataGer[23,1:10]
z2 = dataGer[275,1:10]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "DE.csv", row.names = FALSE)

#FRANCE
#Data Import 
dataFr = read_excel(paste(dataPath, "\\France_2020_with_removed_accent.xlsx", sep=""))
dataFr$date = as.Date(dataFr$date, "%y/%m/%d")

z = dataFr[23,1:11]
z2 = dataFr[278,1:11]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "FR.csv", row.names = FALSE)


#ITALY
#Data Import 
dataIt = read_excel(paste(dataPath, "\\Italy_2020.xlsx", sep=""))
dataIt$date = as.Date(dataIt$date, "%y/%m/%d")

z = dataIt[23,]
z2 = dataIt[276,]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "IT.csv", row.names = FALSE)


#SPAIN
#Data Import 
dataSp = read_excel(paste(dataPath, "\\Spain_2020.xlsx", sep=""))
dataSp$date = as.Date(dataSp$date, "%y/%m/%d")

z = dataSp[23,]
z2 = dataSp[278,]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "SP.csv", row.names = FALSE)


#UK
#Data Import 
dataUk = read_excel(paste(dataPath, "\\UK_2020.xlsx", sep=""))
dataUk$date = as.Date(dataUk$date, "%y/%m/%d")

z = dataUk[23,]
z2 = dataUk[275,]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "UK.csv", row.names = FALSE)


#US
#Data Import 
dataUs = read_excel(paste(dataPath, "\\US_2020.xlsx", sep=""))
dataUs$date = as.Date(dataUs$date, "%y/%m/%d")

z = dataUs[22,]
z2 = dataUs[273,]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "US.csv", row.names = FALSE)


#Switzerland
#Data Import 
dataCh = read_excel(paste(dataPath, "\\Switzerland_2020.xlsx", sep=""))
dataCh$date = as.Date(dataCh$date, "%y/%m/%d")

z = dataCh[22,]
z2 = dataCh[273,]

growth = (z2[,-1] - z[,-1]) / z[,-1] * 100

write.csv(growth, "CH.csv", row.names = FALSE)
